package com.hospital.KT_Activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.hospital.activity.R;
import com.hospital.adapter.DoctorEvaluateAdapter;
import com.hospital.adapter.DoctorIntroductionAdapter;

import java.lang.reflect.Field;

public class DoctorIntroductionActivity extends Activity {
    private LinearLayout head_back;
    private  TextView head_title,tv_back;
    private ListView reservation_diagnosis_lv,doctor_evaluate_lv;


    private DoctorIntroductionAdapter doctorIntroductionAdapter;
    private DoctorEvaluateAdapter doctorEvaluateAdapter;
    private View searchview;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.doctor_introduction);

        head_back = (LinearLayout)findViewById(R.id.head_back);
        head_title = (TextView)findViewById(R.id.head_title);
        tv_back = (TextView)findViewById(R.id.tv_back);

        reservation_diagnosis_lv =(ListView)findViewById(R.id.reservation_diagnosis_lv);
        doctor_evaluate_lv =(ListView)findViewById(R.id.doctor_evaluate_lv);

        head_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });



        doctorIntroductionAdapter = new DoctorIntroductionAdapter(DoctorIntroductionActivity.this, R.layout.reservation_diagnosis_item);
        reservation_diagnosis_lv.setAdapter(doctorIntroductionAdapter);

        doctorEvaluateAdapter = new DoctorEvaluateAdapter(DoctorIntroductionActivity.this, R.layout.evaluate_item);
        doctor_evaluate_lv.setAdapter(doctorEvaluateAdapter);

        reservation_diagnosis_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent doctorIntroductionIntent = new Intent(DoctorIntroductionActivity.this,ReservationConfirmActivity.class);
                startActivity(doctorIntroductionIntent);
            }
        });

        //SearchView
        SearchView search = (SearchView)findViewById(R.id.searchView1);
        //search.setIconifiedByDefault(false);
        //search.setSubmitButtonEnabled(true);
        //改变SearchView输入文字颜色
        int id = search.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView textView = (TextView) search.findViewById(id);
        textView.setTextColor(Color.WHITE);

        //设置提示文字的颜色,这里走了点奇招,用Html类方法
        search.setQueryHint(Html.fromHtml("<font color = #ffffff>" + getResources().getString(R.string.search_value) + "</font>"));
        //修改搜索图标
        try{
            Class<?> argClass=search.getClass();
            Field mSearchButton = argClass.getDeclaredField("mSearchButton");
            mSearchButton.setAccessible(true);
            ImageView searchImg = (ImageView) mSearchButton.get(search);
            searchImg.setImageResource(R.drawable.sy13);
        } catch(Exception e){

        }



        search.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClearHeader(true);
                if(searchview==null){
                    searchview = view ;
                }
                ViewGroup.LayoutParams para = view.getLayoutParams();
                para.height =94;
                view.setLayoutParams(para);
            }
        });

        search.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
                ClearHeader(false);
                if(searchview!=null) {
                    ViewGroup.LayoutParams para = searchview.getLayoutParams();
                    para.height = 40;
                    searchview.setLayoutParams(para);
                }
                return false;
            }
        });


        search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return true;
            }
        });
    }

    private void ClearHeader(boolean flag){
        if(flag){
            head_title.setVisibility(View.INVISIBLE);
            tv_back.setVisibility(View.INVISIBLE);
        }else{
            head_title.setVisibility(View.VISIBLE);
            tv_back.setVisibility(View.VISIBLE);
        }
    }
}
